from core import LOGGER
from control.ElectricRelay import ElectricRelay
import config.hardware
class ControlManager:
    '''电池管理系统控制管理器，用于实现充放电控制与保护功能'''
    def __init__(self,manager) -> None:
        LOGGER.info('正在初始化电池控制设备...')
        self.manager = manager
        self.chargeRelay = ElectricRelay(config.hardware.params.control.ChargePin)
        self.chargeRelay.setup()
        self.dischargeRelay = ElectricRelay(config.hardware.params.control.DisChargePin)
        self.dischargeRelay.setup()
        pass
    def charge(self,chargeState):
        '''启动或停止充电'''
        if(chargeState):
            LOGGER.info('电池开始充电')
            self.chargeRelay.on()
        else:
            LOGGER.info('电池停止充电')
            self.chargeRelay.off()
        pass
    def discharge(self,dischargeState):
        '''启动或停止放电'''
        if(dischargeState):
            LOGGER.info('电池开始放电')
            self.dischargeRelay.on()
        else:
            LOGGER.info('电池停止放电')
            self.dischargeRelay.off()
    def destroy(self):
        self.chargeRelay.destroy()
        self.dischargeRelay.destroy()